package org.chen.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.chen.dto.TtsInstructionTemplateDTO;
import org.chen.entity.TtsInstructionTemplate;
import org.chen.mapper.TtsInstructionTemplateMapper;
import org.chen.service.TtsInstructionTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class TtsInstructionTemplateServiceImpl extends ServiceImpl<TtsInstructionTemplateMapper, TtsInstructionTemplate> implements TtsInstructionTemplateService {

    @Autowired
    private TtsInstructionTemplateMapper templateMapper;

    @Override
    public List<TtsInstructionTemplateDTO> getAllTemplates() {
        List<TtsInstructionTemplate> templates = templateMapper.selectList(null);
        return templates.stream().map(this::convertToDTO).collect(Collectors.toList());
    }

    private TtsInstructionTemplateDTO convertToDTO(TtsInstructionTemplate template) {
        TtsInstructionTemplateDTO dto = new TtsInstructionTemplateDTO();
        dto.setId(template.getTemplateId());
        dto.setName(template.getName());
        dto.setTemplate(template.getTemplateContent());
        return dto;
    }
}